﻿using VisionDesigner.HPFeaturePatMatch;
using VM.Common.Helper;

namespace Plugin.Matching
{
    [Serializable]
    public class ParamModel : NotifyPropertyBase
    {
        public Dictionary<string, string> ParamMap = new Dictionary<string, string>
        {
            { "考虑极性", "Yes" },
            { "不考虑极性", "No" },
        };

        #region 高精度匹配参数

        private int _AngleStart = -180;
        public int AngleStart
        {
            get
            {
                return _AngleStart;
            }
            set
            {
                Set(ref _AngleStart, value);
                ParamInt["AngleStart"] = value;
            }
        }

        private int _AngleEnd = 180;
        public int AngleEnd
        {
            get
            {
                return _AngleEnd;
            }
            set
            {
                Set(ref _AngleEnd, value);
                ParamInt["AngleEnd"] = value;
            }
        }

        private Dictionary<string, int> _paramInt = new Dictionary<string, int>();
        public Dictionary<string, int> ParamInt
        {
            get { return _paramInt; }
            set { Set(ref _paramInt, value); }
        }

        private Dictionary<string, double> _paramDouble = new Dictionary<string, double>();
        public Dictionary<string, double> ParamDouble
        {
            get { return _paramDouble; }
            set { Set(ref _paramDouble, value); }
        }

        private Dictionary<string, Array> _paramArray = new Dictionary<string, Array>();
        public Dictionary<string, Array> ParamArray
        {
            get { return _paramArray; }
            set { Set(ref _paramArray, value); }
        }

        private Dictionary<string, object> _paramEnum = new Dictionary<string, object>();
        public Dictionary<string, object> ParamEnum
        {
            get { return _paramEnum; }
            set { Set(ref _paramEnum, value); }
        }

        #endregion

        public ParamModel()
        {
            // 整型数据
            ParamInt.Add("MaxMatchNum", 1);
            ParamInt.Add("AngleStart", -180);
            ParamInt.Add("AngleEnd", 180);
            ParamInt.Add("MaxOverlap", 40);
            ParamInt.Add("MatchExtentRate", 0);
            ParamInt.Add("TimeOut", 0);
            ParamInt.Add("MatchThresholdHigh", 40);
            ParamInt.Add("ImportantScoreThreshold", 50);
            // 浮点型数据
            ParamDouble.Add("MinScore", 0.50);
            ParamDouble.Add("ScaleXStart", 1.00);
            ParamDouble.Add("ScaleXEnd", 1.00);
            ParamDouble.Add("ScaleYStart", 1.00);
            ParamDouble.Add("ScaleYEnd", 1.00);
            //  Enum数据
            ParamArray.Add("Polarity", Enum.GetValues(typeof(HPFeaturePolarity)));
            ParamEnum.Add("Polarity", HPFeaturePolarity.考虑极性);
        }

        public void UpdateParam(CHPFeaturePatMatchTool cHPFeaturePatMatchTool)
        {
            // 整型数据
            foreach (var pair in ParamInt)
            {
                string key = pair.Key;
                string value = pair.Value.ToString();
                cHPFeaturePatMatchTool.SetRunParam(key, value);
            }

            // 浮点型数据
            foreach (var pair in ParamDouble)
            {
                string key = pair.Key;
                string value = pair.Value.ToString();
                cHPFeaturePatMatchTool.SetRunParam(key, value);
            }

            // Enum数据
            foreach (var pair in ParamEnum)
            {
                string key = pair.Key;
                string value = pair.Value.ToString();
                if (ParamMap.ContainsKey(value))
                {
                    cHPFeaturePatMatchTool.SetRunParam(key, ParamMap[value]);
                }
            }
        }
    }

    /// <summary>
    /// 匹配极性模式
    /// </summary>
    [Serializable]
    public enum HPFeaturePolarity
    {
        考虑极性,
        不考虑极性
    }



}
